<template>
	<view class="special-enter-page page">
		<image class="top-bg" :src="cloudStorage+'index/top-bg.png'"></image>
		<CustomNav :isBack="true" :color="titleColor" :topBgColor="topBgColor" title="联系我们"></CustomNav>
		<view class="white-block">
			<view class="info-block">
				<view class="info-item">
					<view class="title-item">
						<view class="must">*</view>
						<view class="title">我要留言</view>
					</view>
					<textarea maxlength="300" placeholder-style="height:200rpx;" placeholder="请填写您要留言的内容..."
						v-model="form.content" class="form-ctrl"></textarea>
				</view>
				<view class="info-item">
					<view class="title-item">
						<view class="title">图片上传</view>
					</view>
					<view class="upload">
						<view v-for="(item,index) in form.picList" class="image-item">
							<image mode="aspectFit" :src="item" class="img">
							</image>
							<view @click="closeImg(index,1)" style="display: inline;">
								<view class="iconfont">
									<image :src="cloudStorage+'index/delete.png'" class="delete">
									</image>
								</view>
							</view>
						</view>
						<view class="upload-content" v-if="form.picList.length<5" @click="chooseImage('picList',5)">
							<image :src=" cloudStorage+'index/upload.png'" class="upload">
							</image>
						</view>
					</view>
				</view>
			</view>
			<view class="btn-block">
				<view @click="submit" class="btn normal">提交</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		uploadFile
	} from '@/api/file.js'
	import {
		validate
	} from '@/util/validate';
	export default {
		data() {
			return {
				titleColor: '#000',
				topBgColor: 'rgba(0,0,0,0)',
				form: {
					content: '',
					picList: []
				},
				rule: {
					content: {
						name: '留言',
						required: true,
					},
				}
			}
		},
		methods: {
			// 删除图片
			closeImg(index, e) {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '是否删除当前文件',
					success: function(res) {
						if (res.confirm) {
							that.form.picList.splice(index, 1);
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.special-enter-page {
		width: 100%;

		.top-bg {
			width: 100%;
			height: 480rpx;
		}

		.white-block {
			min-height: calc(100vh - 430rpx);
			position: relative;
			margin-top: -50rpx;
			padding: 30rpx;
			width: 100%;
			border-radius: 20px 20px 0 0;
			background: #F7F6F9;

			.info-block {
				background-color: #fff;
				padding: 30rpx;
				border-radius: 20rpx;

				.info-item {
					margin-bottom: 30rpx;

					.title-item {
						display: flex;
						align-items: center;
						margin-bottom: 30rpx;

						.must {
							color: #EA0000;
						}
					}

					.form-ctrl {
						border: 1rpx solid #D6D6D6;
						padding: 10rpx;
						border-radius: 10rpx;
					}

					.upload {
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;

						.image-item {
							width: calc((100% - 20rpx) / 2);
							margin-right: 20rpx;
							display: flex;
							flex-direction: row;

							.img {
								width: 100%;
								height: 200rpx;
								border-radius: 20rpx;
							}

							.iconfont {
								.delete {
									width: 20px;
									height: 20px;
									position: absolute;
									margin-left: -30rpx;
								}
							}
						}

						.image-item:nth-child(2n) {
							margin-right: 0;
						}

						.delete-item {
							width: 100%;
							display: flex;
							justify-content: flex-end;

							.delete {
								width: 20px;
								height: 20px;
								position: absolute;
							}
						}

						.upload-content {
							position: relative;
							background: #F6F6F6;
							border-radius: 5px;
							width: calc((100% - 20rpx) / 2);
							height: 200rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							margin-top: 20rpx;

							.title {
								position: absolute;
								top: 50%;
								left: 50%;
							}

							.upload {
								width: 90rpx;
								height: 90rpx;
							}
						}
					}
				}
			}

			.btn-block {
				display: flex;
				align-items: center;

				.btn {
					margin: 30rpx auto;
				}
			}
		}
	}
</style>